-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add wp_get_theme_data_template_parts
: create public API to access templateParts
from theme.json
#4971
Add wp_get_theme_data_template_parts
: create public API to access templateParts
from theme.json
#4971
Conversation
wp_get_theme_template_part_metadata
wp_get_theme_template_part_metadata
: create public API to access templateParts
in theme.json
This is what the perf tests report:
In the past, I was told the PR's perf job was not reporting data for the own PR, so I am not sure I should trust these numbers? @felixarntz Should I still run my benchmark locally? |
@oandregal the benchmarks reported in the screenshots that you've pasted are comparing WP 6.1.1 (the baseline) with your specific commit, so it's not measuring the impact of this specific change. This limitation is something we've got a ticket to address, but have not done so yet, so taking an individual benchmark if you can would be helpful. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @oandregal, that looks like a great enhancement! Curious to see the benchmark results.
I left two points of feedback below.
@felixarntz @joemcgill this is ready: created the trac ticket, provided testing instructions and a performance report. Performance-wise, this has less impact than I originally thought. It is still valuable, though. Specially, because that the main reason for this PR is to introduce a public method to retrieve data from |
Side-notes about performance report:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @oandregal, looks good to go now code-wise, except one small docs inaccuracy.
I have no idea, but that's definitely something we should research more. I wonder whether there's a notable difference in how the two environments set up the test sites? Otherwise, there's a good chance it is because the automated workflow used for Codevitals uses a headless browser, while |
🤔 I just realized the test data in use by CI is different from the “dummy” content that comes by default. I'd need to use that dataset to know whether it affected these tests. |
I just tried
|
@felixarntz btw, all your feedback has been incorporated. Would you 🟢 this when you have the time, so I can continue follow-up work? |
wp_get_theme_template_part_metadata
: create public API to access templateParts
in theme.json
wp_get_theme_data_template_parts
: create public API to access templateParts
in theme.json
wp_get_theme_data_template_parts
: create public API to access templateParts
in theme.json
wp_get_theme_data_template_parts
: create public API to access templateParts
from theme.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @oandregal!
@oandregal Related to this change, @swissspidy shared some relevant feedback on how creating more and more individual wrapper functions for |
Happy to re-evaluate caching, though, we need the individual functions: they are the public API. Given the discussion around caching doesn't modify the API, I'm going to commit this to continue follow-up work. Please, let the conversation continue. So, caching: the resolver already caches data. The issue is that it has to invalidate some of it once per request, resulting in some expensive processes having to run twice. I'm looking into changing how it works to make it run once. Take By introducing the public APIs (and caching "at the edge" when it makes sense, such as for settings, styles, templateParts, etc.) I'm hoping to be able to decouple some of the internal processes that theme.json classes do, removing the unnecessary ones depending on the data being accessed, making sure caches are use effectively, etc. Hope this helps? |
A class can be a public API too, we don‘t have to add functions for everything. My concern was mostly that I‘m worried we‘ll end up creating X new functions each with its own caching wrapper around that class, leading to poor API design and lots of repetition |
I know. Though, note that
I understand, those are valid concerns I also have. For reference, this is the plan. Note that the plan is not to have a micro-method for everything. The plan is to have five methods. One per top-level keys that can exists in a {
"settings": {},
"styles": {},
"templateParts": {},
"customTemplates": {},
"patterns": {}
} And the public API:
The rationale for this is that each piece has its own requirements (translated or not translated, how sanitization works, etc.). By having these methods, we can improve how things work by refactoring the private classes/processes as needed without breaking backwards compatibility. Does this overview alleviate some of your concerns? |
Co-authored-by: Felix Arntz <[email protected]>
Commited at https://core.trac.wordpress.org/changeset/56385 |
Part of WordPress/gutenberg#45171
Trac ticket: https://core.trac.wordpress.org/ticket/59003
What
This PR adds a new public function
wp_get_theme_template_part_metadata
to offer access to metadata stored undertemplateParts
intheme.json
.Why
There is a no public function to get access to that data, so consumers need to resort to private APIs. This follows the steps of
wp_get_global_settings
,wp_theme_has_theme_json
, orwp_get_theme_directory_pattern_slugs
.How
It creates a new function that uses the private calls and substitutes all instances of the old one in the codebase.
Performance
This proves to be a small improvement (less than 5%) in the tests performed.
Tested loading a single post (hello world) with a site configured as production (
WP_DEBUG
,SCRIPT_DEBUG
,WP_DEBUG_LOG
,WP_DEBUG_DISPLAY
tofalse
).Taking advantage of the new function, it adds a cache following the steps of similar functions such
wp_get_global_settings
orwp_get_global_stylesheet
. This results in a reduction of calls toWP_Theme_JSON_Resolver::get_theme_data
from 15 to 8.In terms of benchmarking with "production" sites, I've done the same test using different tools for comparison.
benchmark-server-timing
benchmark-web-vitals
TTFB
LCP
LCP-TTFB
curl
How to test
Using the TwentyTwentyThree theme:
And then:
theme.json
of the theme by removing the "post-meta" template part declared intemplateParts
.theme.json
).Commit message